<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>东财强势股池</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">			
			nav a{	
			padding: 1em 1em;
			letter-spacing: -100px;			
			}			  
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}					  
			#towrite {margin-top:-10px}	
			table{
			width:460px; 
			border-collapse:collapse; 
			text-align:center;
			}
			td,th{border:1px solid #696969}					
		</style>		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script> 
		<script>
			var day = new Date();
			var tt = "";						
			window.onload = function() {			
			mymonth = day.getMonth()+1;
			myday = day.getDate();
			if(mymonth >= 10){mymonth = mymonth;}else{mymonth = "0" + mymonth;}
			if(myday >= 10){myday = myday;}else{myday = "0" + myday;}
			tt = day.getFullYear() + "-" + mymonth + "-" + myday;
					
			getSource(1);
			changeStyle();
			}
								
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource(0);					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","15:15")						
				},
				60000);
			})
			
			function changeStyle() {
				var obj	 = document.getElementById("towrite");	
				obj.style.left= "0px"; 				
				obj.style.width= "500px";
				//obj.style.height= "620px";						
				obj.style.fontSize="12px";
			}
			
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function UnUnicode(str) {
					return unescape(str.replace(/\\/g, "%"));
				}			
			
			function cDayFunc(dp) { 
				var date = dp.cal.getNewDateStr();            
				BookingRmk(date);//调用其它函数并带上参数                
			}
			
			function BookingRmk(date){         				
				tt = date;							
				getSource(0);
			}
			
			var trid = "";
			function changeCss(obj,hid,id){						
				var tlist = document.getElementById(id).getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = "#252528"; 					
				}
				trid = hid;
				var tr = document.getElementById(hid);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			function hover(){  //鼠标经过
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){						
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头
							if(this.id != trid){  //过滤选中行
								this.style.background="#252528";
							}else{
								this.style.background="#483D8B";
							}
						}						
					}					
				}
			}			
			
			
			function keepTwoDecimal(num) {  
				   var result = parseFloat(num);  
				   if (isNaN(result)) {  
					   //alert('传递参数错误，请检查！');  
					   return false;  
				   }  
				   result = Math.round(num * 100) / 100;  
				   return result;  
			};
		
			function NumberTransform(num) { 
				var result = num;
               if(Math.abs(num) > 100000000){
			    result = num / 100000000;
				result = result.toFixed(2) + "亿";
			   }else if(Math.abs(num) > 10000){
			    result = num/10000;
				result = result.toFixed(2) + "万";
			   }				   
               return result;  
			};	
			
			function updated() {  //判断最后交易日
				var day = new Date(tt);							
				for (i = 1; i < 100; i++){	//节假日																										
					if(i > 1){
						day.setTime(day.getTime() - 24*60*60*1000);							
					}	
					tt = day.Format("yyyy-MM-dd");
					//alert(tt);
					var url = "http://push2ex.eastmoney.com/getTopicQSPool?cb=callbackdata3686089&ut=7eea3edcaed734bea9cbfc24409ed989&dpt=wz.ztzt&Pageindex=0&pagesize=100&sort=zdp%3Adesc&date=" + tt.replace(/-/g,""); 
					var xhr = new XMLHttpRequest();	
					xhr.open("GET", url, false);//同步 
					xhr.send(null)																										
					var data1 = xhr.responseText;					
					if(data1.indexOf('"data":null') == -1){
						break;
					}
				}
			}	
			
			var fx = "";
			var fs = "";
			var x = "";
			var gl = "";  //高亮
			function getSource(s) {
				updated();			
				div = document.getElementById('towrite');
				div.innerHTML = '<font size="2">东财强势股池&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><input style="width: 120px;" type="text" id="PriceDate" name="PriceDate" class="Wdate" onFocus="WdatePicker({ onpicking: cDayFunc})" />';		
				var p1 = "<a href='javascript:void(0)' id='px1' onclick='getSource(" + "\"1\"" + ")'>" + " 涨幅" + "</a>";
				var p2 = "<a href='javascript:void(0)' id='px2' onclick='getSource(" + "\"2\"" + ")'>" + "涨停统计" + "</a>";
				var p3 = "<a href='javascript:void(0)' id='px3' onclick='getSource(" + "\"3\"" + ")'>" + "涨停统计2" + "</a>";
				div.innerHTML = div.innerHTML + "<p>排序（" + p1 + p2 + p3 + "）</p>";					
				//document.getElementById("PriceDate").value = tt;				
				if(s != 0){
					if(fs != s){  //切换类别 清零					
						fx = 0;
					}				
					fs = s;	
					x = s;
				}
				
				aObj = document.getElementById('px' + x);
				gl = aObj.innerText;
				gl = gl.replace(" ","").replace("2","");
				if(s != 0){				
					if(fx == "1"){
						aObj.innerText = aObj.innerText + "↑";						
						fx = 0;				
					}else{
						aObj.innerText = aObj.innerText + "↓";						
						fx = 1;
					}	
				}else{
					if(fx == "1"){
						aObj.innerText = aObj.innerText + "↓";						
									
					}else{
						aObj.innerText = aObj.innerText +  "↑";						
						
					}	
				}				
				aObj.style.color = "#FFA07A";
				
				var px = "";
				if(x == 1){
					if(fx == 1){
						px = "zdp%3Adesc";
					}else{
						px = "zdp%3Aasc";
					}				
				}				
				if(x == 2 || x == 3){
					if(fx == 1){
						px = "zttj%3Adesc";
					}else{
						px = "zttj%3Aasc";
					}								
				}
							
				var url = "http://push2ex.eastmoney.com/getTopicQSPool?cb=callbackdata3686089&ut=7eea3edcaed734bea9cbfc24409ed989&dpt=wz.ztzt&Pageindex=0&pagesize=100&sort=" + px + "&date=" + tt.replace(/-/g,""); 
				
				if (window.XMLHttpRequest) {
						xmlHttp = new XMLHttpRequest();				
					} else {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");				
					}				
					xmlHttp.onreadystatechange = writeSource;
					xmlHttp.open("GET", url, true);
					xmlHttp.send(null);			
			}
			
			function writeSource() { 
				if (xmlHttp.readyState == 4 ) {         					
					var data = xmlHttp.responseText					
					//document.write(data);	
									
					if(data.indexOf('"data":null') == -1){
						//data = data.replace(/ /g,"").match(/\"pool\"(\S*)\}\);/)[1];
						//data = '{"data"' + data.replace(/"zttj":{"days"/g,'"days"').replace(/},"hybk"/g,',"hybk"');
						data = data.replace(/ /g,"").match(/\"pool\":(\S*)\}\}\);/)[1];
						data = data.replace(/"zttj":{"days"/g,'"days"').replace(/},"hybk"/g,',"hybk"');
						if(x != 3){
							data = data.replace(/(\{\").*?(?=\})/g,function(word){ 				
								str = word.match(/\{(\S*)/)[1];
								var ztcs = str.split(',')[16].split(':')[1];
								var days = str.split(',')[15].split(':')[1];								
								if(ztcs >= 2){								
									return "{" + str.split(',')[0] + "," +			
									str.split(',')[2] + ","	+														
									str.split(',')[6] + ","	+
									str.split(',')[8] + ","	+								
									'"zttj":"' + ztcs + "/" + days + '",' + 
									str.split(',')[17];								
								};
							});													
						}else{						
							data1 = data.replace(/(\{\").*?(?=\})/g,function(word){ 				
								str = word.match(/\{(\S*)/)[1];
								var ztcs = str.split(',')[16].split(':')[1];
								var days = str.split(',')[15].split(':')[1];								
								if(ztcs >= 2){
									if(ztcs == days){								
										return "{" + str.split(',')[0] + "," +			
										str.split(',')[2] + ","	+														
										str.split(',')[6] + ","	+
										str.split(',')[8] + ","	+								
										'"zttj":"' + ztcs + "/" + days + '",' + 
										str.split(',')[17];	
									}									
								};
							});												
							data2 = data.replace(/(\{\").*?(?=\})/g,function(word){ 				
								str = word.match(/\{(\S*)/)[1];
								var ztcs = str.split(',')[16].split(':')[1];
								var days = str.split(',')[15].split(':')[1];								
								if(ztcs >= 2){
									if(ztcs != days){								
										return "{" + str.split(',')[0] + "," +			
										str.split(',')[2] + ","	+														
										str.split(',')[6] + ","	+
										str.split(',')[8] + ","	+								
										'"zttj":"' + ztcs + "/" + days + '",' + 
										str.split(',')[17];	
									}									
								};
							});
							data = data1 + data2;		
						}
						data = data.replace(/,undefined}/g,"").replace(/\[undefined},/g,'[').replace("}][{","},{");
						<!-- if(x == 3 && fx == 0){ -->
							<!-- document.write(data); -->
						<!-- } -->
						
						var json = JSON.parse(data);				
						//创建table					
						var table=document.createElement("table");										
						var thead=document.createElement("thead");
						table.appendChild(thead);					
						var tr=document.createElement("tr");
						thead.appendChild(tr);					
						
						var m = 0;
						var v = 0;
						var b = 0;
						for(var key in json[0]){  //表头
							key = key.replace('ct','涨停次数').replace('c','代码').replace('n','名称').replace('zdp','涨幅%').replace('ltsz','流通市值');
							key = key.replace('days','统计天数').replace('zttj','涨停统计').replace('hybk','行业板块');												
							
							var th=document.createElement("th");						
							th.innerHTML=key;						
							tr.appendChild(th);
							if(gl == key.replace("%","")){
								v = m;
								th.style.color = "#FF6633";	
							}
							if(key == "行业板块"){
								b = m;
								th.style.color = "#FFA500";	
							}
							m++;
						}
											
						var tbody=document.createElement("tbody");					
						table.appendChild(tbody);
						
						//遍历json
						for(var i = 0; i < json.length; i++){					
							var tr=document.createElement("tr");						
							var p = 1;
							var dm = "";
							var mc = "";
							for(var key in json[i]){ //行元素遍历						
								var td=document.createElement("td");							
								if(p == 1){  //代码列
									dm = json[i][key];
									td.innerHTML="<a href=http://www.treeid/code_" + dm + " onclick='changeCss(this,\"" + dm + "\",\"gg\")'>" + dm + "</a>";
									tr.id = json[i][key];
								}else if(p == 2){	//名称列							
									mc = json[i][key];
									td.innerHTML="<a href=http://www.treeid/code_" + dm + " onclick='changeCss(this,\"" + dm + "\",\"gg\")'>" + mc + "</a>";
								}else if(p == 3){
									td.innerHTML=keepTwoDecimal(json[i][key]);
								}else if(p == 4){
									td.innerHTML=NumberTransform(json[i][key]);
								}else{
									td.innerHTML=json[i][key];
								}
																
								var rc = json[i][key];
								if(p == 1){  //代码列
									dm = rc;
									tr.id = dm;
								}else if(p == 3){
									rc = keepTwoDecimal(rc);
								}else if(p == 4){
									rc = NumberTransform(rc);
								}							
								td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeCss(this,\"" + dm + "\",\"gg\")'>" + rc + "</a>";
							
							
								if(p == v + 1){							
									td.getElementsByTagName("a")[0].style.color = "#FF6633";
								}
								if(p == b + 1){							
									td.getElementsByTagName("a")[0].style.color = "#FFA500";
								}							
								tr.appendChild(td);
								p++;
							}						
							tbody.appendChild(tr);
						}					
						var div = document.getElementById("towrite");									
						div.appendChild(table);
						table.id = "gg";					
				
					}					
					document.getElementById("PriceDate").value = tt;
					hover();
				}
			}	
						
		</script>
	</head>

	<body>
		<div id="towrite" class="fixedBox">			
		</div>	
	</body>
</html>